package org.catspaw.cherubim.text.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 正则表达式工具类
 * @author 孙宁振 sunningzhen@gmail.com
 * @version 1.0 2011-4-17
 */
public final class RegexUtils {

	public static final String	REGEX_EMAIL			= "^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$";
	public static final String	REGEX_USERNAME		= "^\\w{3,16}$";
	public static final String	REGEX_URL			= "^[a-zA-z]+://(\\w+(-\\w+)*)(\\.(\\w+(-\\w+)*))*(\\?\\S*)?$";
	public static final String	REGEX_ZH_PHONE		= "(^[0-9]{3,4}\\-[0-9]{7,8}$)|(^[0-9]{7,8}$)|(^\\([0-9]{3,4}\\)[0-9]{7,8}$)|(^0{0,1}13[0-9]{9}$)";
	public static final String	REGEX_ZH_POSTCODE	= "\\d{6}";

	private RegexUtils() {
	}

	public static boolean checkPattern(String input, String regEx) {
		if (input == null) {
			return false;
		}
		Pattern p = Pattern.compile(regEx);
		Matcher m = p.matcher(input);
		return m.matches();
	}

	public static boolean checkString(String input, int min, int max) {
		String regExp = "^.{" + min + "," + max + "}$";
		return checkPattern(input, regExp);
	}
}
